package com.tanhua.server.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.tanhua.common.pojo.UserInfo;
import com.tanhua.common.utils.UserThreadLocal;
import com.tanhua.server.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 陈功炳
 * @since 2021/12/3 18:28
 */
@Service
public class MyCenterService {

    @Autowired
    private UserInfoService userInfoService;


    public UserInfoVo queryUserInfoByUserId(Long userId) {
        if(userId == null){
            //如果id为null，就表示查询当前用户信息
            userId = UserThreadLocal.get().getId();
        }

        //查询用户信息
        UserInfo userInfo = userInfoService.queryInfoByUserId(userId);
        if (userInfo == null){
            return null;
        }

        UserInfoVo userInfoVo = BeanUtil.copyProperties(userInfo, UserInfoVo.class, "marriage");
        userInfoVo.setGender(userInfo.getSex().toString().toLowerCase());
        userInfoVo.setMarriage(StrUtil.equals("已婚",userInfo.getMarriage()) ? 1:2);

        return userInfoVo;
    }
}
